import request from '@/utils/request'

// 消息查询参数
export interface MessageQueryParams {
  current?: number
  size?: number
  type?: number
  status?: number
}

// 发送消息请求
export interface SendMessageRequest {
  type: number
  title: string
  content: string
  receiverId: number
  priority?: number
  tags?: string
}

// 批量发送消息请求
export interface BatchSendMessageRequest {
  type: number
  title: string
  content: string
  receiverIds: number[]
  priority?: number
}

// 广播消息请求
export interface BroadcastMessageRequest {
  type: number
  title: string
  content: string
}

// 消息API
export const messageApi = {
  // 分页查询消息
  getMessagePage: (params: MessageQueryParams) => {
    return request.get('/messages/page', { params })
  },

  // 获取未读消息数量
  getUnreadCount: () => {
    return request.get('/messages/unread-count')
  },

  // 获取最新消息
  getLatestMessages: (limit?: number) => {
    return request.get('/messages/latest', { params: { limit } })
  },

  // 发送消息
  sendMessage: (data: SendMessageRequest) => {
    return request.post('/messages/send', data)
  },

  // 批量发送消息
  batchSendMessage: (data: BatchSendMessageRequest) => {
    return request.post('/messages/batch-send', data)
  },

  // 标记消息为已读
  markAsRead: (id: number) => {
    return request.put(`/messages/${id}/read`)
  },

  // 批量标记消息为已读
  batchMarkAsRead: (ids: number[]) => {
    return request.put('/messages/read-batch', { ids })
  },

  // 全部标记为已读
  markAllAsRead: () => {
    return request.put('/messages/read-all')
  },

  // 删除消息
  deleteMessage: (id: number) => {
    return request.delete(`/messages/${id}`)
  },

  // 批量删除消息
  batchDeleteMessage: (ids: number[]) => {
    return request.delete('/messages/batch', { data: { ids } })
  },

  // 系统广播消息
  broadcastMessage: (data: BroadcastMessageRequest) => {
    return request.post('/messages/broadcast', data)
  }
} 